*PUBLIC CHOICE final models replication 04-09-16*

*Indonesia data models*
use "UDBP Public Choice repdata Indonesia.dta", clear

*Table 1*
*model 1*
nbreg pirinc_elec3yr c.marginl c.gridcoastdistance port_cnt i.year malaccadummy nlightavg temp precavg pirinc_movavg splag_pirinc, cluster(gid)
est store ins1 

*model 2, only year before election and election year*
nbreg piracy_t_tmin1 c.marginl c.gridcoastdistance port_cnt i.year malaccadummy nlightavg temp precavg pirinc_movavg splag_pirinc, cluster(gid)
est store ins2

*Figure 3 and table 1, coefficient plot and table*
lab var marginl "Margin"
lab var gridcoastdistance "Distance"
coefplot (ins1, lab(model 1))  (ins2, lab(model 2)) ,  ///
 coeflabels(marginl="Margin, legislative" *.ecav_dum="Political violence" *.marginl##i.ecav_dum="Margin*violence" *.marginl##c.gridcoastdistance="Margin*distance" port_cnt="Ports" gridcoastdistance="Distance, coast" malaccadummy="Malacca dummy" nlightavg="Night lights, t-1" temp="Temperature, t-1" precavg="Rain, t-1" pirinc_movavg="Lag piracy, 3 year average" splag_pirinc="Spatial lag piracy") ///
 order (marginl c.marginl##c.gridcoastdistance *.gridcoastdistance *.ecav_dum  c.marginl##i.ecav_dum )  xline(0, lcolor()) drop(_cons) level(95) legend(pos(4))  ciopts(recast(rcap)) saving(INSresults, replace)

lab var marginl "Margin of victory, national lower house, buffers, CLEA"
lab var gridcoastdistance "Distance grid centroid and coast, km"

esttab ins1 ins2  using "Tab1.rtf", drop (_cons) indicate() star(+ 0.10 * 0.05) obslast stats(aic bic) se  nocon title(Table 1: Event Count Regression of  Piracy and Elections in Indonesia) nonumbers label  b(%10.3f) r2 nonotes addnotes("Clustered standard errors in parentheses.") replace 

*Figure 4, margins at various distances, predicted probabilities*
nbreg pirinc_elec3yr c.marginl c.gridcoastdistance port_cnt i.year malaccadummy nlightavg temp precavg pirinc_movavg splag_pirinc, cluster(gid)
lab var gridcoastdistance "Distance coast"
margins, atmeans at(marginl=(0(0.005)0.48) gridcoastdistance=(0 180)) vsquish
marginsplot, recast(line)  plot1opts(lpattern(l)) legend(pos(6) rows(1) size(small)) plot2opts(lpattern(-) )  recastci(rline)  ciopts(color(gs13))  ///
addplot(scatter where marginl if e(sample)&margintag==1, ms(none)  mlwidth(vthin) mlab(pipe) mlabpos() ///
legend( order(3 "Distance=0km" 4 "Distance=180km") pos(6)) ////
xtitle("Margin of victory, legislative", size(small)) title("", size(small))  )

*Table 2: Robustness***
*Model 3, control for contentious event on land*
nbreg pirinc_elec3yr c.marginl i.ecav_dum port_cnt c.gridcoastdistance i.year malaccadummy  nlightavg temp precavg pirinc_movavg splag_pirinc, cluster(gid)
est store ins3

*model 4 with interaction w/ contentious event on land*
nbreg pirinc_elec3yr c.marginl##i.ecav_dum port_cnt c.gridcoastdistance i.year malaccadummy  nlightavg temp precavg pirinc_movavg splag_pirinc, cluster(gid)
est store ins4

*model 5, effect of margins on past piracy*
nbreg pirinc_movavg c.marginl  port_cnt c.gridcoastdistance i.year malaccadummy nlightavg temp precavg,   cluster(gid)
est store ins5

*model 6, provincial elections, 1999 only*
nbreg pirinc_elec3yr c.marginl3  port_cnt c.gridcoastdistance  malaccadummy  nlightavg temp precavg pirinc_movavg splag_pirinc, cluster(gid)
est store ins6

*model 7, Run model with first differences of night lights, temperature, and precipitation*
nbreg pirinc_elec3yr c.marginl c.gridcoastdistance port_cnt i.year malaccadummy nlight_diff temp_diff prec_diff pirinc_movavg splag_pirinc, cluster(gid)
est store ins7

*model 8, DV=dummy*
nbreg pirinc_dum c.marginl c.gridcoastdistance port_cnt i.year malaccadummy nlightavg temp precavg pirinc_movavg splag_pirinc, cluster(gid)
est store ins8

esttab  ins3 ins4 ins5 ins6 ins7 ins8 using "Tab2.rtf", drop (_cons) indicate() star(+ 0.10 * 0.05) obslast stats(aic bic) se  nocon title(Table 2: Event Count Regression of Maritime Piracy and Elections in Indonesia, Robustness) nonumbers label  b(%10.3f) r2 nonotes addnotes("Clustered standard errors in parentheses.") replace 

lab var marginl3 "Margin of victory, provincial, buffers, Brancati"
lab var gridcoastdistance "Distance grid centroid and coast, km"

*Table 3: Cross-national model of elections and piracy*
use "UDBP Public Choice repdata crossnational.dta", clear
xtnbreg pirattack pirmovavg  l.election i.year l.avg_temp l.avg_precip l.ports_wpi l.goveffect ln_coastline l.lncgdp l.lnpop if year<2011, fe
est store ins9 
xtnbreg pirattack pirmovavg  election i.year l.avg_temp l.avg_precip l.ports_wpi l.goveffect ln_coastline l.lncgdp l.lnpop if year<2011, fe
xtnbreg pirattack pirmovavg  f.election i.year l.avg_temp l.avg_precip l.ports_wpi l.goveffect ln_coastline l.lncgdp l.lnpop if year<2011, fe

xtnbreg pirattack pirmovavg  l.enep i.year l.avg_temp l.avg_precip l.ports_wpi l.goveffect ln_coastline l.lncgdp l.lnpop if year<2011, fe
est store ins10
esttab  ins9 ins10  using "Tab3.rtf", drop (_cons) indicate() star(+ 0.10 * 0.05) obslast stats(aic bic) se  nocon title(Table 3: Cross-National Event Count Regression of Maritime Piracy, 1995-2010) nonumbers label  b(%10.3f) r2 nonotes addnotes("Clustered standard errors in parentheses.") replace 

*Variables created for marginal effects plots* 
gen pipe= "|"
gen where=-0.01
drop where
egen margintag = tag(marginl)
drop margintag

*Robustness for memo*

*Election year t, t-1, t+1*
use "UDBP Public Choice repdata crossnational.dta", clear
xtnbreg pirattack pirmovavg  l.election i.year l.avg_temp l.avg_precip l.ports_wpi l.goveffect ln_coastline l.lncgdp l.lnpop if year<2011, fe
est store memo1 
xtnbreg pirattack pirmovavg  election i.year l.avg_temp l.avg_precip l.ports_wpi l.goveffect ln_coastline l.lncgdp l.lnpop if year<2011, fe
est store memo2 
xtnbreg pirattack pirmovavg  f.election i.year l.avg_temp l.avg_precip l.ports_wpi l.goveffect ln_coastline l.lncgdp l.lnpop if year<2011, fe
est store memo3
esttab  memo1 memo2 memo3  using "Memo1.rtf", drop (_cons) indicate() star(+ 0.10 * 0.05) obslast stats(aic bic) se  nocon title(Table 3: Cross-National Event Count Regression of Maritime Piracy, 1995-2010) nonumbers label  b(%10.3f) r2 nonotes addnotes("Clustered standard errors in parentheses.") replace 


